package com.patni.frame.util.edge;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JWindow;

import com.patni.frame.util.Common;
import com.sun.awt.AWTUtilities;

public class StaticChips {

	public static JWindow NCHIP = null;
	private  static Integer[] NBounds = new Integer[4];
	public static JWindow ECHIP = null;
	private  static Integer[] EBounds = new Integer[4];
	public static JWindow SCHIP = null;
	private  static Integer[] SBounds = new Integer[4];
	public static JWindow WCHIP = null;
	private  static Integer[] WBounds = new Integer[4];
	
	private static Integer[] rectangle = new Integer[4];
	private static Graphics2D g2d;
	private static BasicStroke bs;
	public static void init(){
		System.out.println("StaticChips begin to init");
		
		rectangle[0] = -10;
		rectangle[1] = -10;
		rectangle[2] = 0;
		rectangle[3] = 0;
			
		float[] dash1 = {1.0f};
		bs = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
		
		NCHIP  = new JWindow(){
			private static final long serialVersionUID = 10110L;

			@Override
			public void paint(Graphics g) {
				super.paint(g);
				g2d=(Graphics2D)g;
				g2d.setStroke(bs);

				g2d.draw(new Rectangle(rectangle[0] - NBounds[0],rectangle[1] - NBounds[1],rectangle[2],rectangle[3]));
				g2d.draw(new Rectangle(rectangle[0]-1 - NBounds[0],rectangle[1]-1 - NBounds[1],rectangle[2]+2,rectangle[3] +2));
				g2d.draw(new Rectangle(rectangle[0]-2 - NBounds[0],rectangle[1]-2 - NBounds[1],rectangle[2]+4,rectangle[3]+4));
			}
		};
		
		ECHIP  = new JWindow(){
			private static final long serialVersionUID = 200L;

			@Override
			public void paint(Graphics g) {
				super.paint(g);
				g2d=(Graphics2D)g;
				g2d.setStroke(bs);

				g2d.draw(new Rectangle(rectangle[0] - EBounds[0],rectangle[1] - EBounds[1],rectangle[2],rectangle[3]));
				g2d.draw(new Rectangle(rectangle[0]-1 - EBounds[0],rectangle[1]-1 - EBounds[1],rectangle[2]+2,rectangle[3] +2));
				g2d.draw(new Rectangle(rectangle[0]-2 - EBounds[0],rectangle[1]-2 - EBounds[1],rectangle[2]+4,rectangle[3]+4));
			}
		};
		
		SCHIP  = new JWindow(){
			private static final long serialVersionUID = 1987L;

			@Override
			public void paint(Graphics g) {
				super.paint(g);
				g2d=(Graphics2D)g;
				g2d.setStroke(bs);

				g2d.draw(new Rectangle(rectangle[0] - SBounds[0],rectangle[1] - SBounds[1],rectangle[2],rectangle[3]));
				g2d.draw(new Rectangle(rectangle[0]-1 - SBounds[0],rectangle[1]-1 - SBounds[1],rectangle[2]+2,rectangle[3] +2));
				g2d.draw(new Rectangle(rectangle[0]-2 - SBounds[0],rectangle[1]-2 - SBounds[1],rectangle[2]+4,rectangle[3]+4));
			}
		};
		
		WCHIP  = new JWindow(){
			private static final long serialVersionUID = 10000L;

			@Override
			public void paint(Graphics g) {
				super.paint(g);
				g2d=(Graphics2D)g;
				g2d.setStroke(bs);

				g2d.draw(new Rectangle(rectangle[0] - WBounds[0],rectangle[1] - WBounds[1],rectangle[2],rectangle[3]));
				g2d.draw(new Rectangle(rectangle[0]-1 - WBounds[0],rectangle[1]-1 - WBounds[1],rectangle[2]+2,rectangle[3] +2));
				g2d.draw(new Rectangle(rectangle[0]-2 - WBounds[0],rectangle[1]-2 - WBounds[1],rectangle[2]+4,rectangle[3]+4));
			}
		};
		
		NCHIP.setAlwaysOnTop(true);
		ECHIP.setAlwaysOnTop(true);
		SCHIP.setAlwaysOnTop(true);
		WCHIP.setAlwaysOnTop(true);
		
		AWTUtilities.setWindowOpaque(NCHIP, false);
		AWTUtilities.setWindowOpaque(ECHIP, false);
		AWTUtilities.setWindowOpaque(SCHIP, false);
		AWTUtilities.setWindowOpaque(WCHIP, false);
		
		NCHIP.setVisible(true);
		ECHIP.setVisible(true);
		SCHIP.setVisible(true);
		WCHIP.setVisible(true);
		
		System.out.println("StaticChips init successful!	");
	}
	
	public static void  prepareForPaint(Integer[] rectangle){
		StaticChips.rectangle = rectangle;
		NBounds[0] = rectangle[0] - 2;
		NBounds[1] = rectangle[1] - 2;
		NBounds[2] = rectangle[2] + 4;
		NBounds[3] = 3;
		
		EBounds[0] = rectangle[0] + rectangle[2] ;
		EBounds[1] = rectangle[1] - 2;
		EBounds[2] = 3;
		EBounds[3] = rectangle[3] + 4;
		
		SBounds[0] = rectangle[0] - 2;
		SBounds[1] = rectangle[1] + rectangle[3];
		SBounds[2] = rectangle[2] + 4;
		SBounds[3] = 3;
		
		WBounds[0] = rectangle[0] - 2;
		WBounds[1] = rectangle[1] - 2;
		WBounds[2] = 3;
		WBounds[3] = rectangle[3] + 4;
		
		NCHIP.setBounds(NBounds[0], NBounds[1], NBounds[2], NBounds[3]);
		ECHIP.setBounds(EBounds[0], EBounds[1], EBounds[2], EBounds[3]);
		SCHIP.setBounds(SBounds[0], SBounds[1], SBounds[2], SBounds[3]);
		WCHIP.setBounds(WBounds[0], WBounds[1], WBounds[2], WBounds[3]);

	}
}
